package com.example.homeworkmutualevaluation.Dao;

import com.example.homeworkmutualevaluation.Entity.File;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface FileDao extends JpaRepository<File, Integer> {
    @Transactional
    @Modifying
    @Query(value = "INSERT INTO file(`id`, `name`, `data`) VALUES (?1, ?2, ?3)", nativeQuery = true)
    int insert(String id, String name, byte[] data);
    @Query(value = "SELECT * FROM file WHERE `id`=?1", nativeQuery = true)
    File findById(String id);
    @Query(value = "SELECT `name` FROM file WHERE `id`=?1", nativeQuery = true)
    String findNameById(String id);
}
